// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './common/route.js'
import store from './store'
import App from './App'
import { _getDate } from "./common/util"
import moment  from "moment"
import MintUi from 'mint-ui';

Vue.use(MintUi);
import 'jquery'
//Set this to false to prevent the production tip on Vue startup.
Vue.config.productionTip = false
Vue.use(VueRouter)
const router = new VueRouter({  routes });
/* 滚动监听指令*/
let scrollHandle;
window.moment = moment;
Vue.directive('scroll', {
  bind: (el, binding) => {
    let handle = binding.value;
    if (typeof handle === 'function') {
      window.addEventListener('scroll', scrollHandle = () => {
        handle()
      });
    }
  },
  unbind: (el, binding) => {
    window.removeEventListener('scroll', scrollHandle);
    scrollHandle = null;
  }
});
Vue.mixin({
  methods: {
    /*
     * 提示
     * msg:String,必须,提示内容
     * icon:String,可无,自定义icon图标类名,若传值则提示位于屏幕中心
     */
    toast(msg, icon = '') {
      let data = { message: msg, position: 'bottom', duration: 1800 };
      if (icon && icon.length > 0) {
        data.iconClass = icon;
        data.position = 'middle';
      }
      MintUi.Toast(data);
    },
  }
  })
Vue.component('v-list', {
  template: `<mt-loadmore ref="loadmore" v-infinite-scroll="loadmore" infinite-scroll-disabled="isend" infinite-scroll-distance="120" infinite-scroll-immediate-check="false" :auto-fill="false" :top-method="reload">
      <!-- :bottom-method="loadmore" :bottom-all-loaded="isend"  :bottom-pull-text="'加载更多'" :bottom-drop-text="'释放加载'"-->
     <div class="clearfix"><slot></slot></div>
     <p class='noMore' v-show="isend">没有更多了</p>
    </mt-loadmore>`,
  props: {
    loadHandle: { type: Function },
    moreHandle: { type: Function },
    isend: { type: Boolean, default: false },
    moreHandling: { type: Boolean, default: false },
  },
  methods: {
    reload() {
      this.loadHandle(this.$refs.loadmore);
      this.$refs.loadmore.onTopLoaded();
    },
    loadmore() {
      if (this.moreHandling === true) return false;
      this.moreHandle(this.$refs.loadmore);
      this.$refs.loadmore.onBottomLoaded();
    }
  }
})
/* eslint-disable no-new */
const vm = new Vue({
  el: '#app',
  router, store,
  template: '<App/>',
  components: { App },
  data: {
    downloadPage: false,
    ISAPP: false,//判断是否在APP中打开h5页面
    ISIOS: false,//判断移动端是否为ios
    ISWX: false, //判断是否在微信中
    share: {
      title: '', // 分享标题
      desc: '', // 分享描述
      link: '', // 分享链接
      imgUrl: '', // 分享图标
    },
  },
  created() {
    // 组件创建完后获取数据，
    // 此时 data 已经被 observed 了
    this._initAgent();
  },
  methods: {
    _initAgent() {
      let u = navigator.userAgent;
      this.ISAPP = u.indexOf('platform/app') !== -1;
      this.ISIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
      this.ISWX = /micromessenger/.test(u.toLowerCase());
    },
    hideDownload() {
      this.downloadPage = false;
    },
  },

})
